<?php
namespace app\hospital\model;
use app\model\Bookinfo;
use think\facade\Db;
use think\facade\Request;
use think\Model;

class doctor extends Model{
function getsubjectidAttr($v){
    $subject=[];
    $subject0=Db::name("subjecttype")->select();
    foreach ($subject0 as $v0){
        $subject=$subject+array($v0['subjectid']=>$v0['subjectname']);
    }
    return $subject[$v];
}
function del(){
    $id=Request::param('id');
    $data=Db::name('doctor')->where('id',$id)->select();
    if($data->isEmpty()){
        echo "该患者未就医";
        return false;
    }
    else{
        $res=Db::name('doctor')->where('id',$id)->delete();
        return $res;
    }
}
    function search()
    {
        $key=Request::param('key');
        //  $data=Bookinfo::where("bookname","like","%".$key."%")->paginate(['list_rows'=>4,'query'=>Request::param()]);

        $data=doctor::withSearch(['doctorname','postlevel','major'],[
            'doctorname'=>$key,
            'postlevel'=>$key,
            'major'=>$key
        ])->paginate(['list_rows'=>3,'query'=>Request::param()]);
//        dump(Db::getlastsql());
        // halt($data->toArray());
        return $data;
    }

    function searchdoctornameAttr($q,$v){
        //  halt($q,$v,$d);
        $q->where('doctorname','like','%'.$v.'%');

    }
    function searchpostlevelAttr($q,$v){
        $q->whereor('postlevel','like','%'.$v.'%');
    }
    function searchmajorAttr($q,$v){
        $q->whereor('major','like','%'.$v.'%');
    }
}